package com.glory.erp.invoice.supplier.dao.impl;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

import com.glory.erp.invoice.supplier.dao.SupplierDao;
import com.glory.erp.invoice.supplier.bean.Supplier;
import com.glory.erp.invoice.supplier.bean.SupplierQuery;
import com.glory.erp.auth.base.BaseDaoImpl;
import com.glory.erp.auth.base.BaseQueryModel;

public class SupplierDaoImpl extends BaseDaoImpl<Supplier> implements
		SupplierDao {

	public void doQbc(DetachedCriteria dc, BaseQueryModel qm) {
		SupplierQuery sqm = (SupplierQuery) qm;
		if (sqm.getName() != null && sqm.getName().trim().length() > 0) {
			dc.add(Restrictions.like("name", "%" + sqm.getName() + "%"));
		}
		if (sqm.getContact() != null && sqm.getContact().trim().length() > 0) {
			dc.add(Restrictions.eq("contact", sqm.getContact()));
		}
		if (sqm.getTele() != null && sqm.getTele().trim().length() > 0) {
			dc.add(Restrictions.eq("tele", sqm.getTele()));
		}
		if (sqm.getNeeds() != null && sqm.getNeeds() != -1) {
			dc.add(Restrictions.eq("needs", sqm.getNeeds()));
		}
	}

	public List<Supplier> findAllUnion() {
		String hql = "select distinct s from GoodsType gt join gt.supplier s";
		return this.getHibernateTemplate().find(hql);
	}

	public List<Supplier> findAllUnionTwo() {
		String hql = "select distinct s from Goods g join g.goodsType gt join gt.supplier s";
		return this.getHibernateTemplate().find(hql);
	}
}